package com.duan.common.utils.redis;

import java.io.*;

public class ScriptUtil {

    public static String buildScript(String readFile) {

        StringBuilder sb = new StringBuilder();
        try (
                InputStream inputStream = ScriptUtil.class.getClassLoader().getResourceAsStream(readFile);
                InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
                BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
                ){

            String readLine = "";
            while ((readLine = bufferedReader.readLine()) != null) {
                sb.append(readLine).append(System.lineSeparator());
            }
        } catch (IOException e){
            e.printStackTrace();
        }

        return sb.toString();
//        URL resource = ScriptUtil.class.getClassLoader().getResource(readFile);
//        String fileName = resource.getFile();
//        System.out.println(fileName);
//        File file = new File(fileName);
//
//        Long length = file.length();
//        byte[] bytes = new byte[length.intValue()];
//
//        FileInputStream in = null;
//        try {
//            in = new FileInputStream(file);
//            in.read(bytes);
//            return new String(bytes, "UTF-8");
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        } finally {
//            try {
//                in.close();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }
//        return null;
    }

}
